package com.hugegis.CustomAdapter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.hugegis.SmarHMETER.R;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.SimpleAdapter;

public class CheckBoxSimpleAdapter extends SimpleAdapter {

	public HashMap<Integer, Boolean> checkState =null;


	public CheckBoxSimpleAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to) {
		super(context, data, resource, from, to);
		checkState= new HashMap<Integer, Boolean>();
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		View view = super.getView(position, convertView, parent);
		CheckBox check = (CheckBox) view.findViewById(R.id.meter_box_check);
		check.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				if (isChecked) {
					checkState.put(position, isChecked);
				} else {
					checkState.remove(position);
				}
			}
		});
		check.setChecked((checkState.get(position) == null ? false : true));

		return view;
	}

}
